package com.weavernorth.attendance;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;


/**
 * @program: ecology_erdos
 * @description: 考勤异常提醒(每日提醒前一日考勤异常信息 ( 旷工 、 漏签 、 迟到 、 早退 ))
 * @author: zm
 * @create: 2020-01-06 15:38
 **/


public class AbnormalAttendDay extends BaseCronJob {
    public static Log log = LogFactory.getLog(AbnormalAttendDay.class.getName());

    @Override
    public void execute() {
        //数据库操作
        RecordSet rs = new RecordSet();
        //考勤异常工具类
        AbnormalUtil abnormalUtil=new AbnormalUtil();

        //查询前一天考勤异常的人员
        String sql = "select kqdate,resourceid,belatemins ,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotbeginworkcheckmins from kq_format_detail " +
                " where kqdate=(select to_char(sysdate - interval '1' day, 'yyyy-mm-dd') from dual) " +
                " and (belatemins !=0 or graveBeLateMins !=0 or leaveearlymins!=0 or graveLeaveEarlyMins!=0 or absenteeismmins!=0 or forgotcheckMins!=0 or forgotbeginworkcheckmins!=0)";
        log.info("查询前一天考勤异常数据:" + sql);
        rs.executeQuery(sql);
        while (rs.next()) {
            StringBuffer strMess = new StringBuffer("您");
            //考勤日期
            String strKqdate=Util.null2String(rs.getString("kqdate"));
            //人员id
            String strResourceid = Util.null2String(rs.getString("resourceid"));
            //迟到时长
            Double douBelatemins = Util.getDoubleValue(rs.getString("belatemins"));
            if (douBelatemins != 0) {
                strMess.append(strKqdate+",迟到时长为:" + douBelatemins + "分钟");
            }
            //严重迟到时长
            Double douGraveBeLateMins = Util.getDoubleValue(rs.getString("graveBeLateMins"));
            if (douGraveBeLateMins != 0) {
                strMess.append(strKqdate+",严重迟到时长为:" + douGraveBeLateMins + "分钟");
            }
            //早退时长
            Double douLeaveearlymins = Util.getDoubleValue(rs.getString("leaveearlymins"));
            if (douLeaveearlymins != 0) {
                strMess.append(strKqdate+",早退时长为:" + douLeaveearlymins + "分钟");
            }
            //严重早退时长
            Double douGraveLeaveEarlyMins = Util.getDoubleValue(rs.getString("graveLeaveEarlyMins"));
            if (douGraveLeaveEarlyMins != 0) {
                strMess.append(strKqdate+",严重早退时长为:" + douGraveLeaveEarlyMins + "分钟");
            }
            //旷工时长
            Double douAbsenteeismmins = Util.getDoubleValue(rs.getString("absenteeismmins"));
            if (douAbsenteeismmins != 0) {
                strMess.append(strKqdate+",旷工时长为:" + douAbsenteeismmins + "分钟");
            }
            //下午漏签时长
            Double douForgotcheckMins = Util.getDoubleValue(rs.getString("forgotcheckMins"));
            if (douForgotcheckMins != 0) {
                strMess.append(strKqdate+",下午漏签,");
            }
            //上午漏签时长
            Double douMornForgotcheckMins = Util.getDoubleValue(rs.getString("forgotbeginworkcheckmins"));
            if (douMornForgotcheckMins != 0) {
                strMess.append(strKqdate+",上午漏签,");
            }
            strMess.append("请您及时处理!");
            log.info("拼接的异常提醒信息:"+strMess);
            //创建考勤异常提醒流程
            abnormalUtil.createAbnormal(strResourceid,strMess.toString());



        }

    }
}
